package com.example.controller;

import com.example.common.Result;
import com.example.entity.Address;
import com.example.entity.CheckNumber;
import com.example.service.CheckNumberService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(value = "用户闯关次数", tags = {"用户闯关次数的增删改查"})
@RequestMapping("/checknumber")
public class CheckNumberController
{
    @Resource
    private CheckNumberService checkNumberService;
    /**
     * 新增
     */
    @ApiOperation(value = "增加闯关信息", notes = "返回是否成功")
    @PostMapping("/add")
    public Result add(@RequestBody CheckNumber checkNumber) {
        checkNumberService.add(checkNumber);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除闯关信息", notes = "返回是否成功")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "id",
                    value = "要删除的id,如'1'"
            )
    })
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        checkNumberService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除闯关信息", notes = "返回是否成功")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        checkNumberService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "更新闯关次数信息", notes = "返回是否成功")
    @PutMapping("/update")
    public Result updateById(@RequestBody CheckNumber checkNumber) {
        checkNumberService.updateById(checkNumber);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "通过id查询闯关次数信息", notes = "返回Models中的用户闯关次数类型")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "id",
                    value = "要查询的用户闯关次数d,如'1'"
            )
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = CheckNumber.class,reference = "CheckNumber")
    })
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        CheckNumber checkNumber = checkNumberService.selectById(id);
        return Result.success(checkNumber);
    }

    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有符合特征的闯关次数信息", notes = "返回Models中的用户闯关次数类型的数组")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = CheckNumber.class,reference = "CheckNumber")
    })
    @GetMapping("/selectAll")
    public Result selectAll( CheckNumber checkNumber) {
        List<CheckNumber> checkNumberList = checkNumberService.selectAll(checkNumber);
        return Result.success(checkNumberList);
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询所有符合特征的用户闯关次数信息", notes = "返回Models中的用户闯关次数信息的分页数组")
    @ApiImplicitParams({
            @ApiImplicitParam(
                    name = "pageNum",
                    value = "要查询的页码,默认为'1'"
            ),
            @ApiImplicitParam(
                    name = "pageSize",
                    value = "每页尺寸,默认为'10'"
            )
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = CheckNumber.class,reference = "CheckNumber")
    })
    @GetMapping("/selectPage")
    public Result selectPage(CheckNumber checkNumber,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<CheckNumber> pageInfo = checkNumberService.selectPage(checkNumber, pageNum, pageSize);
        return Result.success(pageInfo);
    }
}
